package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.GiftEntity;
import com.example.yiwei.crm.util.NetWorkUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/4/28.
 */

public class GiftJson {
    public static List<GiftEntity> get(String result){
        List<GiftEntity> list ;
        GiftEntity giftEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                giftEntity = new GiftEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("CID03")){
                    giftEntity.setCname(json.getString("CID03"));
                }
                if (json.has("KPA02")){
                    giftEntity.setBfname(json.getString("KPA02"));
                }
                if (json.has("CTS01L")){
                    giftEntity.setCdata(json.getString("CTS01L"));
                }
                if (json.has("KDB02")){
                    giftEntity.setGiftname(json.getString("KDB02"));
                }
                if (json.has("KDB03")){
                    giftEntity.setGiftmonery(json.getInt("KDB03"));
                }

                list.add(giftEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
